<?php 
	$dsn = "mysql: host=localhost;dbname=tk173;charset=utf8";
	$pdo = new PDO($dsn,"root","root");
	$sql = "select id,title,date,source from article ";
	$stat= $pdo->query($sql);
	$total =$stat->rowCount();
	$pages = ceil($total/10);
	$page = $_GET['p'];
	$page = $page>$pages?$pages:$page;
	$page = $page<1?1:$page;


	$start = ($page-1) *10;
  	$sql.= " limit {$start},10";
  	 $res = $pdo->query($sql);
  	 $data =$res->fetchAll(2);
  	 $resp['data'] = $data;
  	 $resp['page'] = $page;


  	 echo json_encode($resp);

 ?>